/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.mail.manage.controller;

import info.peigen.hotpot.common.core.result.manage.WebResult;
import info.peigen.hotpot.component.data.repository.beetlsql.filter.ManageDataAspect;
import info.peigen.hotpot.component.mail.manage.controller.form.MailTemplateManageCreateForm;
import info.peigen.hotpot.component.mail.manage.controller.form.MailTemplateManageDeleteForm;
import info.peigen.hotpot.component.mail.manage.controller.form.MailTemplateManageEditForm;
import info.peigen.hotpot.component.mail.manage.controller.form.MailTemplateManageSearchForm;
import info.peigen.hotpot.component.mail.manage.service.MailTemplateManageService;
import info.peigen.hotpot.component.mail.manage.service.result.MailTemplateCreateResult;
import info.peigen.hotpot.component.mail.manage.service.result.MailTemplateDeleteResult;
import info.peigen.hotpot.component.mail.manage.service.result.MailTemplateEditResult;
import info.peigen.hotpot.component.mail.manage.service.result.info.MailTemplateManageInfo;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.validation.annotation.Valid;

/**
 * <b>(MailTemplateManageController)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@SuppressWarnings("unchecked")
@Valid
@Controller
@Mapping(path = "mailTemplate", method = MethodType.POST)
public class MailTemplateManageController {
    @Inject
    private MailTemplateManageService mailTemplateManageService;

    @Mapping("/")
    @ManageDataAspect
    WebResult<MailTemplateManageInfo> page(@Body MailTemplateManageSearchForm form) {
        return WebResult.setSuccessResult().setInfo(mailTemplateManageService.page(form));
    }

    @Mapping("add")
    @ManageDataAspect
    WebResult<MailTemplateManageInfo> create(@Body MailTemplateManageCreateForm form) {
        MailTemplateCreateResult result = mailTemplateManageService.create(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("edit")
    @ManageDataAspect
    WebResult<MailTemplateManageInfo> edit(@Body MailTemplateManageEditForm form) {
        MailTemplateEditResult result = mailTemplateManageService.edit(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("delete")
    @ManageDataAspect
    WebResult<MailTemplateManageInfo> delete(@Body MailTemplateManageDeleteForm form) {
        MailTemplateDeleteResult result = mailTemplateManageService.delete(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

}